﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using FaceSharp.Api.Types;
using FaceSharp.MVC.Filters;

namespace FaceSharp.MVC.Areas.FacebookApp.Controllers
{
    public class AdministrationController : BaseController
    {
        
        /// <summary>
        /// Page Administrators should be able to edit page application settings at this URL.
        /// </summary>
        /// <returns></returns>
        [FacebookGraphApiFilter(ForceLogin = false)]
        public ActionResult Edit()
        {
            var signedRequest = (SignedRequest)System.Web.HttpContext.Current.Items["SignedRequest"];
            if(signedRequest == null || signedRequest.Page == null || !signedRequest.Page.Admin)
            {
                // This visitor to the page is not an admin, they should not be here.
                RedirectToAction("Index");
            }

            // Because there are no restrictions allowing you to prevent others from installing your page tab application, 
            // it is important to take into account the page id when presenting admin interaces.
            // EXAMPLE:
            // if(signedRequest.Page.Id != 12318581123) RedirectToAction("Index");

            return View();
        }

    }
}
